<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>个人资料</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>
</head>
<body>
<div id="app">
  <div id="blank" class="header shopheader" v-cloak>
      <div v-back.tapmode class="getback"></div>
      <span class="title">添加商品</span>
      <span v-cloak tapmode v-myclick="[1, addcategorygoods]"  style="position:absolute;right:10px;font-size:14px;" v-show="isadd">保存{{index>0?'('+index+')':''}}</span>
  </div>
    <div class="main-container" v-cloak>
      <div class="goods_info" v-for="(good, index) in goods">
        <div class="goods-detail" v-myclick="[good, opebrowser]">
          <div class="goods-pic">
            <img v-image-resize="{src:good.pic}" :key="good.goods_id">
          </div>
          <div class="goods-detail-right">
            <div class="goods-detail-title">{{good.title}}</div>
            <div class="sell-price">
              <div style="float:left;"><span style="color:#666666;">原价：</span><span style="color:#9d0152">￥{{good.prime}}</span></div>
              <div style="float:left;padding-left:5px"><span style="color:#666666;">优惠价格：</span><span style="color:#9d0152">￥{{good.coupon_amount}}</span></div>
              <div style="clear:both"></div>
            </div>
            <div class="goods_number" @click.stop="selectStatus(good)">
              <span style="color:#E5001E">赚&nbsp;{{good.t6_gain_max}}</span>
              <span style="padding-left:10px">销量：{{good.sale_count}}</span>
              <img class="goods-radio" @click.stop="selectStatus(good)"  v-src="'../../image/unselected.png'" v-show="good.select !== 1">
              <img class="goods-confirm" @click.stop="selectStatus(good)" v-src="'../../image/selected.png'" v-show="good.select == 1">
            </div>
          </div>
        </div>
      </div>
        </div>
        <div class="shop-footer" v-show="!isadd" v-cloak>
          <div class="confirm" style="margin-left:30%" v-myclick="[1, addgoods]">确认添加</div>
          <!-- <div class="moremanage" v-myclick="[2, moremanage]">更多管理</div> -->
        </div>
        <lazy-load  v-if="goods.length > 0" style="background-color:#f7f7f7;margin-bottom:65px"
                   count-per-page="20"
                   :arr="goods"
                   :url="url"
                   :param="param"
                   ret-attr="goods"
                   >
        </lazy-load>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/components.js"></script>
<script>
var vm,
    moreActive,
    isselected,
    goodsselected=[],
    category_id,
    index=0,
    isadd=false,
    param,
    goods;

apiready = function () {
  showProgress();
  UIScrollPicture = api.require('UIScrollPicture');
  MNActionButton = api.require('PIActionButton');
  wx = api.require('wx');
  var param = api.pageParam;
      category_id = param.category_id;
      if(!category_id){
        isadd=true;
      }
  setBSImg();
  var data = {
      member_id: getPrefs('member_id'),
      category_id:category_id
  };
  param={
    category_id: param.category_id,
  }
  var callback = function (ret) {
      var home = ret.content;
      goods = home.goods;
      // console.log(JSON.stringify(goods));
      initApp();
      api.parseTapmode();
  };
  pinet.post(URL.getCategorygoodsInfo, data, callback);
  addListeners();
};

function refresh() {
  var data = {
      member_id: getPrefs('member_id')
  };
  var callback = function (ret) {
      var home = ret.content;
      if (vm) {
          vm.goods = home.goods;
          vm.key++;
      } else {
          initApp();
      }
      api.refreshHeaderLoadDone();
  };
  var errback = function () {
      api.refreshHeaderLoadDone();
  };

  pinet.post(URL.getCategorygoodsInfo, data, callback, errback);
}

function initApp() {
    vm = new Vue({
        el: "#app",
        data: {
            moreActive: 1,
            isselected:1,
            goods: goods,
            param:param,
            index:index,
            category_id:category_id,
            url: URL.getCategorygoodsInfo,
        },
        methods: {
            moremanage: function (index) {
              this.moreActive = index;
            },
            selectStatus: function (good) {
              if(good.select == 1){
                good.select = -1;
                goodsselected.remove(good.goods_id);
                index = (index-1);
                vm.index = index;
              }else{
                good.select = 1;
                goodsselected.push(good.goods_id);
                index = (index+1);
                vm.index = index;
              }
            },
            addgoods:function(type){
              if(goodsselected.length<1){
                pinet.alert('请选择商品');
                return;
              }
              api.confirm({
                  title: '提示',
                  msg: "确定添加?",
                  buttons: ['确定添加', '再想想']
              }, function (ret, err) {
                var index = ret.buttonIndex;
                if(index==1){
                  goodsselected = goodsselected.join('|');
                  var data = {
                      member_id: getPrefs('member_id'),
                      goodsselected: goodsselected,
                      category_id:category_id,
                      type:type
                  };
                  var callback = function (ret) {
                    if(ret.errcode==0){
                      var home = ret.content;
                      vm.goods = home.goods;
                      goodsselected= [];
                      api.sendEvent({
                          name: 'savecategory'
                      });
                        closeWin();
                    }
                  };
                  pinet.post(URL.saveCategoryGoods, data, callback);
                }
              });
            },
            addcategorygoods:function(){
              if(goodsselected.length<4){
                pinet.alert('未满四个商品不能进行分类');
                return;
              }
              var key = "addcategorygoods";
              $api.setStorage(key, goodsselected);
              api.sendEvent({
                  name: 'addcategorygoods'
              });
              closeWin();
            },
            opebrowser:function(good){
              if(good.goods_url){
                openWin('shopbrowser',{auctionurl:good.goods_url,good:good})
              }
            },
        },
    });
}
function addListeners() {
    api.addEventListener({
        name: 'viewappear'
    }, function () {
        onPageStart();
    });

    api.addEventListener({
        name: 'viewdisappear'
    }, function (ret, err) {
        onPageEnd();
    });

    api.addEventListener({
        name: 'keyback'
    }, function (ret, err) {
        onPageEnd();
        api.closeWin();
    });
}

</script>
</html>
